from django.contrib.admin import site, ModelAdmin, TabularInline

from bandsite.bandlib.models import Creator, Location, Part, Ensemble, Genre, Year, Piece, LibraryPiece, Programme, Performance, Band

class PieceInline(TabularInline):
   model = Piece
   
class PerformanceInline(TabularInline):
   model = Performance

class CreatorA(ModelAdmin):
   list_display = 'name',

class LocationA(ModelAdmin):
   list_display = 'name',

class PartA(ModelAdmin):
   list_display = 'name',

class EnsembleA(ModelAdmin):
   list_display = 'name',

class GenreA(ModelAdmin):
   list_display = 'name',

class YearA(ModelAdmin):
   list_display = 'name',

class PieceA(ModelAdmin):
   list_display = 'title', 'ensemble', 'genre', 'composer', 'arranger', 'year', 'notes'
   search_fields = 'title',
   list_filter = 'ensemble','genre'
   fieldsets = (
      (None, {'fields': (('title', 'ensemble', 'genre'),
                         ('composer', 'arranger', 'year'),
                         ('notes',))}),
      )

class LibraryPieceA(ModelAdmin):
   list_display = 'index', 'piece', 'location', 'notes',  'rating', 'order', 'flag'
   
class ProgrammeA(ModelAdmin):
   list_display = 'notes',
   inlines = PerformanceInline,

class PerformanceA(ModelAdmin):
   list_display = 'order', 'piece', 'concert'
   filter_list = 'Concert', 

class BandA(ModelAdmin):
   list_display = 'register_date', 'expiry_date', 'user'
   
register = site.register

register(Creator,CreatorA)
register(Location, LocationA)
register(Part, PartA)
register(Ensemble, EnsembleA)
register(Genre, GenreA)
register(Year, YearA)
register(Piece, PieceA)
register(LibraryPiece, LibraryPieceA)
register(Programme, ProgrammeA)
register(Performance, PerformanceA)
register(Band, BandA)

